<?

/***************************************************************************
 Jupiter Content System @ Jupiterportal.com
 Copyright (C) 2005 Cosmin Flavius (highstrike@gmail.com)

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

//-----------------------------------------------------------------
//  Filter Acces Rightes
//-----------------------------------------------------------------

if(isset($is_guest) || isset($is_user) || isset($is_moderator))
{ header("location: $PHP_SELF?i=2"); exit; }

//-----------------------------------------------------------------
//  Vars
//-----------------------------------------------------------------

if(!isset($reglocation)) $reglocation = NULL;
if(!isset($regflag)) $regflag = NULL;

//-----------------------------------------------------------------
//  Add the new user to the database
//-----------------------------------------------------------------

switch($a)
{
	//-----------------------------------------------------------------
	//  Do Add User
	//-----------------------------------------------------------------

	case 1:

		//-----------------------------------------------------------------
		//  Checks and overchecks
		//-----------------------------------------------------------------

		if(!$regusername){ header("location: $PHP_SELF?n=modules/adduser&i=7"); exit; }
		if(!$regpassword){ header("location: $PHP_SELF?n=modules/adduser&i=8"); exit; }
		if($regpassword != $regpassword2){ header("location: $PHP_SELF?n=modules/adduser&i=11"); exit; }
		if(!$regemail){ header("location: $PHP_SELF?n=modules/adduser&i=12"); exit; }
		if(!eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $regemail)){ header("location: $PHP_SELF?n=modules/adduser&i=13"); exit; }

		if(!$regurl) $regurl = NULL;
		if(!$regflag) $regflag = NULL;
		if(!$reglocation) $reglocation = NULL;
		if($regday == 0 || $regmonth == 0 || $regyear == 0) $regage = NULL;
		else $regage = mktime(0,0,0,$regmonth,$regday,$regyear);

		//-----------------------------------------------------------------
		//  MYSQL checks
		//-----------------------------------------------------------------

		$check_user = $db->getLine("SELECT id FROM users WHERE username='".$db->escape($regusername)."'");
		$check_email = $db->getLine("SELECT id FROM users WHERE email='".$db->escape($regemail)."'");

		if($check_user != FALSE){ header("location: $PHP_SELF?n=modules/adduser&i=9"); exit; }
		if($check_email != FALSE){ header("location: $PHP_SELF?n=modules/adduser&i=10"); exit; }

		//-----------------------------------------------------------------
		//  Begin writing the information
		//-----------------------------------------------------------------

		$info['authorization'] = $authorisation;
		$info['username'] = jcm_htmlspecialchars(jcm_stripslashes($regusername));
		$info['password'] = md5($regpassword);
		$info['email'] = jcm_htmlspecialchars(jcm_stripslashes($regemail));
		$info['url'] = jcm_htmlspecialchars(jcm_stripslashes($regurl));
		$info['age'] = $regage;
		$info['flag'] = $regflag;
		$info['location'] = jcm_htmlspecialchars(jcm_stripslashes($reglocation));
		$info['registered'] = time();
		$info['lastvisit'] = time();
		$info['forum_lastvisit'] = time();
		$info['ip'] = find_ip();
		$info['forumposts'] = 0;
		$info['hideemail'] = $reghideemail;
		$info['calendarbday'] = $regcalendarbday;
		$info['status'] = "ready";
		$info['multikey'] = NULL;
		$info['actime'] = NULL;

		$db->insertRow("users",$info);

		//-----------------------------------------------------------------
		//  Add bday to event if 1 was selected
		//-----------------------------------------------------------------

		if($regcalendarbday == 1 && $regage != NULL)
		{
			$get_id = $db->getLine("SELECT id, username FROM users WHERE username = '".$db->escape($regusername)."' AND email = '".$db->escape($regemail)."'");

			$event_db_add['type'] = "bday";
			$event_db_add['user_id'] = $get_id['id'];
			$event_db_add['user_user'] = $get_id['username'];
			$event_db_add['day'] = $regday;
			$event_db_add['month'] = $regmonth;
			$event_db_add['year'] = date("Y");
			$event_db_add['message'] = "Birthday Event";

			$db->insertRow("events",$event_db_add);
		}

		//-----------------------------------------------------------------
		//  Redirect + Trick
		//-----------------------------------------------------------------

		header("location: $PHP_SELF?n=modules/adduser&i=136");

	break;

	//-----------------------------------------------------------------
	//  Show Add User form
	//-----------------------------------------------------------------

	default:

	?>
		<table class="main" cellspacing="1" cellpadding="4">
		<tr class='con1'><td><a href='<?= $PHP_SELF ?>?n=modules/admin'><?= $language['Admin name'] ?></a> &raquo; <?= $language['Add User title'] ?></td></tr>
		</table>
		<table><tr><td></td></tr></table>	
	
		<form method="post" action="<?= $PHP_SELF ?>?n=modules/adduser&a=1">
		<table class="main" cellspacing="1" cellpadding="4" width="100%">
		<col width="40%"><col width="60%">
		<tr class="head"> 
		<td colspan="2" class="head"><?= $language['Add User title'] ?></td>
		</tr>
		<tr class="bottom">
		<td height="21" colspan="2"><?= $language['Add User title2'] ?></td>
		</tr>
		<tr>
		<td class="con1" valign="middle"><span class="hilight"><?= $language['Add User desc16'] ?></span></td>
		<td class="con1" valign="bottom">
		<select class='box' style='width: 100%;' name='authorisation'><option selcted value='1'><?= $language['Add User desc17'] ?></option><option value='2'><?= $language['Add User desc18'] ?></option><option value='3'><?= $language['Add User desc19'] ?></option></select>
		</td>
		</tr>
		<tr>
		<td class="con1" valign="middle"><span class="hilight"><?= $language['Add User desc'] ?></span></td>
		<td class="con1" valign="bottom"><input type="text" name="regusername" style="width:100%" maxlength="25" class="box" tabindex="5"></td>
		</tr>
		<tr>
		<td class="con1" valign="middle"><span class="hilight"><?= $language['Add User desc2'] ?></span></td>
		<td class="con1" valign="bottom"><input type="password" name="regpassword" style="width:100%" maxlength="25" class="box" tabindex="6"></td>
		</tr>
		<tr>
		<td class="con1" valign="middle"><span class="hilight"><?= $language['Add User desc3'] ?></span></td>
		<td class="con1" valign="bottom"><input type="password" name="regpassword2" style="width:100%" maxlength="25" class="box" tabindex="7"></td>
		</tr>
		<tr>
		<td class="con1" valign="middle"><span class="hilight"><?= $language['Add User desc4'] ?></span></td>
		<td class="con1" valign="bottom"><input type="text" name="regemail" style="width:100%" maxlength="35" class="box" tabindex="8"></td>
		</tr>
		<tr class="bottom">
		<td height="21" colspan="2"><?= $language['Add User title3'] ?></td>
		</tr>
		<tr>
		<td class="con1" valign="middle"><?= $language['Add User desc5'] ?></td>
		<td class="con1" valign="bottom"><input type="text" name="regurl" style="width:100%" maxlength="35" class="box" tabindex="9"></td>
		</tr>
		<tr>
		<td class="con1" valign="middle"><?= $language['Add User desc6'] ?><? if(isset($o)) echo "<a href='$PHP_SELF?n=modules/adduser'> {$language['Add User desc7']}</a></td>"; else echo "<a href='$PHP_SELF?n=modules/adduser&o=1'> {$language['Add User desc8']}</a></td>"; echo "<td class='con1' valign='bottom'>"; if(isset($o)) echo "<input type='text' name='reglocation' style='width:100%' maxlength='35' class='box' tabindex='10'>"; else echo "<select name='regflag' style='width:100%' class='box' tabindex='10'>".find_country()."</select>" ?></td>
		</tr>
		<tr>
		<td class="con1" valign="middle"><?= $language['Add User desc9'] ?></td>
		<td class="con1" valign="bottom"><table cellspacing="0" cellpadding="0" width="100%"><tr class='empty'><td width='30%'><select name="regday" class="box" style="width:100%" tabindex='11'><option value='0'></option><? for ($i = 1; $i <= 31; $i++) echo "<option value='$i'>$i</option>\n" ?></select></td><td align='center' width='5%'>-</td><td width='30%'><select name="regmonth" class="box" style="width:100%" tabindex='12'><option value='0'></option><? for ($i = 1; $i <= 12; $i++) echo "<option value='$i'>{$months[$i]}</option>\n" ?></select></td><td align='center' width='5%'>-</td><td width='30%'><select name="regyear" class="box" style="width:100%" tabindex='13'><option value='0'></option><? for ($i = 1900; $i <= date("Y") - 5; $i++) echo "<option value='$i'>$i</option>\n" ?></select></td></tr></table></td>
		</tr>
		<tr>
		<td class="con1" valign="middle"><?= $language['Add User desc10'] ?></td>
		<td class="con1" valign="bottom"><input type="radio" name="reghideemail" value="1" tabindex='14'>&nbsp;<?= $language['Add User desc14'] ?>&nbsp;&nbsp;&nbsp;<input type="radio" name="reghideemail" value="0" checked tabindex='15'>&nbsp;<?= $language['Add User desc15'] ?></td>
		</tr>
		<tr>
		<td class="con1" valign="middle"><?= $language['Add User desc11'] ?></td>
		<td class="con1" valign="bottom"><input type="radio" name="regcalendarbday" value="1" checked tabindex='16'>&nbsp;<?= $language['Add User desc14'] ?>&nbsp;&nbsp;&nbsp;<input type="radio" name="regcalendarbday" value="0" tabindex='17'>&nbsp;<?= $language['Add User desc15'] ?></td>
		</tr>
		<tr>
		<td class="con1"><input type="button" style="width:100" class="box" value="<?= $language['Add User desc12'] ?>" onClick="window.history.go(-1);" tabindex="19"></td>
		<td class="con1" align="right"><input type="submit" style="width:100" class="box" value="<?= $language['Add User desc13'] ?>" tabindex="18"></td>
		</tr>
		<input type="hidden" name="a" value="1">
		</table></form>
		<?
	break;
}

?>